"""
应用模型
"""
from datetime import datetime
from sqlalchemy import Boolean, Column, DateTime, Integer, String, Text, JSON
from sqlalchemy.orm import relationship

from app.core.database import Base


class Application(Base):
    """应用模型"""
    __tablename__ = "applications"

    id = Column(Integer, primary_key=True, index=True)
    name = Column(String(100), unique=True, index=True, nullable=False)
    description = Column(Text)
    app_type = Column(String(50), nullable=False)  # docker, k8s, static
    repository_url = Column(String(500))
    dockerfile_path = Column(String(200))
    build_command = Column(Text)
    start_command = Column(Text)
    health_check_url = Column(String(500))
    health_check_interval = Column(Integer, default=30)
    health_check_timeout = Column(Integer, default=10)
    health_check_retries = Column(Integer, default=3)
    environment_variables = Column(JSON)
    resource_limits = Column(JSON)  # CPU, Memory limits
    ports = Column(JSON)  # Port mappings
    volumes = Column(JSON)  # Volume mounts
    networks = Column(JSON)  # Network configurations
    labels = Column(JSON)  # Custom labels
    is_active = Column(Boolean, default=True)
    created_at = Column(DateTime, default=datetime.utcnow)
    updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
    
    # 关联关系
    deployments = relationship("Deployment", back_populates="application")
